<template>
  <div class="list-table">
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('收款方名称')" prop="payeeName">
        <el-input
          v-model="queryParams.payeeName"
          :placeholder="$t('收款方名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('开户行名称')" prop="depositBank">
        <el-input
          v-model="queryParams.depositBank"
          :placeholder="$t('开户行名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="oaPayeeHistoryList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('收款方名称')" align="center" prop="payeeName" />
      <el-table-column :label="$t('开户行名称')" align="center" prop="depositBank" />
      <el-table-column :label="$t('账户名称')" align="center" prop="accountTitle" />
      <el-table-column :label="$t('银行账号')" align="center" prop="bankNumber" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['oa:payment:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listOaPayeeHistory, delOaPayeeHistory } from '@/api/oa/payment/oaPaymetHistory'

export default {
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 收款历史记录表格数据
      oaPayeeHistoryList: [],
      // 弹出层标题
      title: '收款历史记录',
      // 是否显示弹出层
      formOpen: false,
      // 查询参数
      queryParams: {
        payeeName: undefined,
        depositBank: undefined,
        accountTitle: undefined,
        bankNumber: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询收款历史记录列表 */
    getList() {
      this.loading = true
      listOaPayeeHistory(this.queryParams).then(response => {
        this.oaPayeeHistoryList = response.rows
        this.total = response.total
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        payeeName: undefined,
        depositBank: undefined,
        accountTitle: undefined,
        bankNumber: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(() => {
        const data = {
          payeeName: row.payeeName,
          depositBank: row.depositBank,
          accountTitle: row.accountTitle,
          bankNumber: row.bankNumber
        }
        return delOaPayeeHistory(data)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(() => {
        this.loading = false
      })
    }
  }
}
</script>
